/* Include files. */

extern "C" { 
	#include "standard.h"
	#include "util.h"
	#include "debug.h"
} 

#include "message.h"

/* Local function declarations. */

/* Macro API definitions. */
#define MAX_POOL_SIZE 0

/* Global variable declarations. */

/* Type definitions. */

/* Local function definitions. */

queue<message*> message::pool;

void message::destroy(message* msg)
{
	if (message::pool.size() < MAX_POOL_SIZE)
		message::pool.push(msg);
	else
		delete msg;
}

message * message::create(const char *from, const char *to, u32 session, 
						const char *type, const char *msg)
{
	
	if (message::pool.size()) {
		message *m = message::pool.front();
		message::pool.pop();
		m->reset(from, to, session, type, msg);
		return m;
	}
	else{
		return new message(from, to, session, type, msg);
	}	
}

void message::reset(const char *from, const char *to, u32 session, 
						const char *type, const char *msg)
{
	_from = from;
	_to = to;
	_session = session;
	_type = type;
	_msg = msg;
}


